﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
using System.Collections;
namespace WebVideo.Areas.Admin.Models
{
    public class ReportPointModel
    {
        public int Id { get; set; }

        [Required(ErrorMessage = "Username không được rỗng")]
        [StringLength(50, ErrorMessage = "Tiêu đề phải ít hơn {1} kí tự và lớn hơn {2} kí tự", MinimumLength = 3)]
        public string UserName { get; set; }

        [Required(ErrorMessage = "Số điểm không được rỗng")]
        [RegularExpression("^\\+?\\d+$", ErrorMessage = "Không nhập ký tự , vui lòng nhập số điểm")]
        public int? Pointed { get; set; }

        public DateTime? Date { get; set; }


        public static IEnumerable<EntityReport_Point> Index()
        {
            dbVideoDataContext db = new dbVideoDataContext();
            var query = from p in db.EntityReport_Points
                        orderby p.Date descending
                        select p;
            return query.ToList();
        }
        public static void Delete(int Id)
        {
            dbVideoDataContext db = new dbVideoDataContext();

            EntityReport_Point rp = db.EntityReport_Points.Where(p => p.Id == Id).Single();
            db.EntityReport_Points.DeleteOnSubmit(rp);
            db.SubmitChanges();
        }
        public static void Ban(int Id, int l)
        {
            dbVideoDataContext db = new dbVideoDataContext();

            EntityReport_Point tnew = db.EntityReport_Points.Where(p => p.Id == Id).Single();
            tnew.Status = l;
            db.SubmitChanges();

        }
        public static void Insert(ReportPointModel RP)
        {
            dbVideoDataContext db = new dbVideoDataContext();
            EntityReport_Point rp = new EntityReport_Point();
            rp.UserName = RP.UserName;
            rp.Pointed = RP.Pointed;
            rp.Date = DateTime.Now;
            db.EntityReport_Points.InsertOnSubmit(rp);
            db.SubmitChanges();
        }

        public static ReportPointModel LayModel(int IdRP)
        {
            ReportPointModel Rp = new ReportPointModel();
            dbVideoDataContext db = new dbVideoDataContext();
            EntityReport_Point rp = db.EntityReport_Points.Where(p => p.Id == IdRP).Single();
            Rp.UserName = rp.UserName;
            Rp.Id = rp.Id;
            Rp.Pointed = rp.Pointed;


            return Rp;

        }
        public static void Edit(ReportPointModel RP)
        {
            dbVideoDataContext db = new dbVideoDataContext();
            EntityReport_Point Rp = db.EntityReport_Points.Where(p => p.Id == RP.Id).Single();
            Rp.UserName = RP.UserName;
            Rp.Pointed = RP.Pointed;
            db.SubmitChanges();

        }

    }
}